/*     */ package com.zimbra.qa.unittest;
/*     */ 
/*     */ import com.zimbra.common.util.Log;
/*     */ import com.zimbra.common.util.ZimbraLog;
/*     */ import com.zimbra.cs.account.Account;
/*     */ import com.zimbra.cs.mailbox.DeliveryOptions;
/*     */ import com.zimbra.cs.mailbox.Mailbox;
/*     */ import com.zimbra.cs.mailbox.MailboxManager;
/*     */ import com.zimbra.cs.mailbox.Message;
/*     */ import com.zimbra.cs.mime.ParsedMessage;
/*     */ import com.zimbra.cs.store.Blob;
/*     */ import com.zimbra.cs.store.MailboxBlob;
/*     */ import com.zimbra.cs.store.StoreManager;
/*     */ import com.zimbra.cs.store.file.BlobDeduper;
/*     */ import com.zimbra.cs.store.file.FileBlobStore;
/*     */ import com.zimbra.cs.util.Zimbra;
/*     */ import com.zimbra.cs.volume.Volume;
/*     */ import com.zimbra.cs.volume.VolumeManager;
/*     */ import com.zimbra.znative.IO;
/*     */ import com.zimbra.znative.IO.FileInfo;
/*     */ import java.io.File;
/*     */ import java.util.ArrayList;
/*     */ import java.util.List;
/*     */ import junit.framework.Assert;
/*     */ import junit.framework.TestCase;
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ public final class TestBlobDeduper
/*     */   extends TestCase
/*     */ {
/*  42 */   private static String USER_NAME = "user1";
/*  43 */   private static String TEST_NAME = "TestBlobDeduper";
/*     */   private Mailbox mbox;
/*     */   private Account account;
/*     */   
/*     */   public TestBlobDeduper(String testName) {
/*  48 */     super(testName);
/*     */   }
/*     */   
/*     */   public void setUp() throws Exception
/*     */   {
/*  53 */     super.setUp();
/*  54 */     this.account = TestUtil.getAccount(USER_NAME);
/*  55 */     this.mbox = MailboxManager.getInstance().getMailboxByAccount(this.account);
/*     */     
/*  57 */     cleanUp();
/*     */   }
/*     */   
/*     */   public void testBlobDeduper() throws Exception
/*     */   {
/*  62 */     if (!(StoreManager.getInstance() instanceof FileBlobStore)) {
/*  63 */       ZimbraLog.test.info("Skipping deduper test for non-FileBlobStore");
/*  64 */       return;
/*     */     }
/*  66 */     DeliveryOptions opt = new DeliveryOptions();
/*  67 */     opt.setFolderId(2);
/*  68 */     String[] paths = new String[5];
/*  69 */     Volume vol = VolumeManager.getInstance().getCurrentMessageVolume();
/*  70 */     for (int i = 0; i < 5; i++) {
/*  71 */       Message msg = this.mbox.addMessage(null, new ParsedMessage(("From: test@zimbra.com\r\nTo: to1@zimbra.com\r\nSubject: " + TEST_NAME).getBytes(), false), opt, null);
/*  72 */       paths[i] = msg.getBlob().getLocalBlob().getFile().getPath();
/*     */     }
/*     */     
/*  75 */     for (int i = 0; i < 4; i++) {
/*  76 */       Assert.assertFalse(IO.fileInfo(paths[i]).getInodeNum() == IO.fileInfo(paths[(i + 1)]).getInodeNum());
/*     */     }
/*     */     
/*  79 */     Thread.sleep(1000L);
/*  80 */     BlobDeduper deduper = BlobDeduper.getInstance();
/*  81 */     List<Short> volumeIds = new ArrayList();
/*  82 */     volumeIds.add(Short.valueOf(vol.getId()));
/*  83 */     deduper.process(volumeIds);
/*  84 */     while (deduper.isRunning()) {
/*  85 */       Thread.sleep(1000L);
/*     */     }
/*     */     
/*  88 */     for (int i = 0; i < 4; i++) {
/*  89 */       Assert.assertTrue(IO.fileInfo(paths[i]).getInodeNum() == IO.fileInfo(paths[(i + 1)]).getInodeNum());
/*     */     }
/*     */   }
/*     */   
/*     */   public void tearDown() throws Exception
/*     */   {
/*     */     try {
/*  96 */       cleanUp();
/*     */     }
/*     */     catch (Throwable t)
/*     */     {
/* 100 */       if ((t instanceof OutOfMemoryError)) {
/* 101 */         Zimbra.halt("TestBlobDeduper ran out of memory", t);
/*     */       }
/* 103 */       ZimbraLog.test.error("", t);
/*     */     }
/*     */   }
/*     */   
/*     */ 
/*     */ 
/*     */   private void cleanUp()
/*     */     throws Exception
/*     */   {
/* 112 */     TestUtil.deleteTestData(USER_NAME, TEST_NAME);
/*     */   }
/*     */ }


/* Location:              /home/mint/zimbrastore.jar!/com/zimbra/qa/unittest/TestBlobDeduper.class
 * Java compiler version: 7 (51.0)
 * JD-Core Version:       0.7.1
 */